<?php

namespace Miniprogram\Controller;

use Think\Controller;

class BaseController extends Controller {

    protected $member_id;

    protected $num=10;

    protected $userInfo;

    protected $lang;

    protected $config;

    public function _initialize()

    {

//        $this->member_id=6;

        if (I('get.token') || I('post.token')) {

            $this->userInfo=$this->checkUser();

            $this->member_id=$this->userInfo['id'] ;

        }else{
            error('登录失效');
            exit();
        }

        $this->lang=(I('get.lang'))?I('get.lang'):'cn';

        $this->config=C('lang_cn');



    }

    /*用户检测session过期*/

    protected function checkUser(){

        $member = D('Member');

        /*返回userid*/

        $result = $member->auth();

        if(!$result)

            $this->ajaxReturn(

                array(

                    'rc'=>2,

                    'msg'=>'登录失效',

                    'data'=>array(

                        'auth'=>session('AUTH_USER_STRING')

                    )

                )

            );

        return $result;

    }

    protected function checkId($id,$field=array()){

        if(!$id)

            error($this->config['parr_err']);

        if(!$info=$this->m->field($field)->find($id))

            error($this->config['parr_err']);

        return $info;

    }

    /*通用数据库 增删改 结果反馈*/

    protected function checkRes($res){

        if($res){

            success(array(),$this->config['success']);

        }else {

            error($this->config['error_update']);

        }

    }



}